#include "widget.h"
#include "ui_widget.h"
#include <QLabel>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    ui->tabWidget->setTabsClosable(true);
    QLabel* label1 = new QLabel(ui->tab);
    label1->setText("标签1");
    QLabel* label2 = new QLabel(ui->tab_2);
    label2->setText("标签2");

}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_add_clicked()
{
    QWidget* newWidget = new QWidget();
    int count = ui->tabWidget->count();
    ui->tabWidget->addTab(newWidget,"Tab"+QString::number(count+1));


    QLabel* newLabel = new QLabel(newWidget);
    newLabel->setText(QString("标签")+QString::number(count+1));
    newLabel->resize(100,50);

    ui->tabWidget->setCurrentIndex(count);
}

void Widget::on_pushButton_del_clicked()
{
    int curCount = ui->tabWidget->currentIndex();
    ui->tabWidget->removeTab(curCount);
}
